package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/13.<br><br>
 *
 * 有效的字母异位词
 */
public class Topic242 {
    public static void main(String[] args) {
        Topic242 instance = new Topic242();

        System.out.println(instance.isAnagram("anagram", "nagaram"));
        System.out.println(instance.isAnagram("rat", "car"));
    }

    public boolean isAnagram(String s, String t) {
        int[] map = new int[26];

        for(int i = 0; i < s.length(); i++) {
            map[s.charAt(i) - 'a']++;
        }

        for(int i = 0; i < t.length(); i++) {
            map[t.charAt(i) - 'a']--;
        }

        for(int value : map) {
            if(value != 0) {
                return false;
            }
        }

        return true;
    }
}
